package com.bilibili.juc.completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 如果您有一个线程对象 thread，您可以调用 thread.join() 来等待 thread 线程的完成，并取得结果
 */
public class CompletableFutureAPI3Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        /*CompletableFuture.supplyAsync(() -> {
            return 1;
        }).thenApply(f ->{
            return f + 2;
        }).thenApply(f ->{
            return f + 3;
        }).thenAccept(System.out::println);*/
        //如果您有一个线程对象 thread，您可以调用 thread.join() 来等待 thread 线程的完成，并取得结果
        System.out.println(CompletableFuture.supplyAsync(() -> "resultA")
                .thenRun(() -> {
                }).join());
        System.out.println(CompletableFuture.supplyAsync(() -> "resultB")
                .thenAccept(r -> System.out.println(r)).join());
        System.out.println(CompletableFuture.supplyAsync(() -> "resultC")
                .thenApply(r -> r + " resultD").join());
    }
}

